package org.webdb.webapp.interceptors;

import java.io.Closeable;
import java.io.IOException;
import java.util.Collection;

import javax.ws.rs.WebApplicationException;
import javax.ws.rs.ext.Provider;

import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.spi.interception.MessageBodyWriterContext;
import org.jboss.resteasy.spi.interception.MessageBodyWriterInterceptor;

@Provider
@ServerInterceptor
public class CloseableInterceptor implements MessageBodyWriterInterceptor {

    @SuppressWarnings("unused")
    @Override
    public void write(MessageBodyWriterContext context) throws IOException,
            WebApplicationException {

        boolean closeable = false;
        Object entity = context.getEntity();

        if (entity instanceof Closeable)
            closeable = true;

        if (Collection.class.isAssignableFrom(entity.getClass())) {
            entity.getClass().getGenericInterfaces();
        }

        context.proceed();
    }

}
